<?php
/**
 * @file name : my_string_helper.php
 * @package   :
 * @author    : Vo Thanh Minh
 * @email     : <thanhminhld@yahoo.com - thanhminhld@gmail.com>
 * @copyright : 2011
 *
 */
	if (!defined('BASEPATH')) {
		exit('No direct script access');
	}
	/**
	 * @function array2ParentChildStructor
	 *
	 * This function will return array with structor
	 * Array(
			[0] => Array(parents),
			[1] => Aray(childs of parent),
			[..]
			[n] => Array(childs of parent)
		)
	 *
	 * @param	array $arrGeneral
	 * @param	string $parentFieldName
	 * @return	array
	 */
	if ( ! function_exists('array2ParentChildStructor')) {

		function array2ParentChildStructor($arrGeneral = array(), $parentFieldName = '', $parentId = 0,
										   $arrAddMore = array())
		{
			$arrRet = array();
			if (count($arrGeneral) <= 0) {
				return $arrRet;
			}
			if (strlen($parentFieldName) == 0) {
				return $arrRet;
			}
			foreach($arrGeneral as $key => $element) {
				if (is_object($element) && isset($element->$parentFieldName)) {
					if (count($arrAddMore) > 0) {
						if (isset($arrAddMore['parentUrl'])) {
							$element->parentUrl = $arrAddMore['parentUrl'];
						}
						if (isset($arrAddMore['parentCss']) && $element->$parentFieldName == $parentId) {
							$element->parentCss = $arrAddMore['parentCss'];
							$element->childCss = '';
						} else if (isset($arrAddMore['childCss']) && $element->$parentFieldName != $parentId) {
							$element->parentCss = '';
							$element->childCss = $arrAddMore['childCss'];
						}
					}
					$arrRet[$element->$parentFieldName][] = $element;

				} else if (isset($element[$parentFieldName])) {
					$arrRet[$element[$parentFieldName]][] = $element;
				}
			}
			return $arrRet;
		}
	}
	/**
	 * @function convert2Alias
	 *
	 *
	 *
	 *
	if ( ! function_exists('convert2Alias')) {
		function convert2Alias($cs)
		{
			$marTViet=array("à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă",
			"ằ","ắ","ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề"
			,"ế","ệ","ể","ễ",
			"ì","í","ị","ỉ","ĩ",
			"ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ"
			,"ờ","ớ","ợ","ở","ỡ",
			"ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ",
			"ỳ","ý","ỵ","ỷ","ỹ",
			"đ",
			"À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă"
			,"Ằ","Ắ","Ặ","Ẳ","Ẵ",
			"È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ",
			"Ì","Í","Ị","Ỉ","Ĩ",
			"Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ"
			,"Ờ","Ớ","Ợ","Ở","Ỡ",
			"Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ",
			"Ỳ","Ý","Ỵ","Ỷ","Ỹ",
			"Đ"," ", "'");
			$marKoDau=array("a","a","a","a","a","a","a","a","a","a","a"
			,"a","a","a","a","a","a",
			"e","e","e","e","e","e","e","e","e","e","e",
			"i","i","i","i","i",
			"o","o","o","o","o","o","o","o","o","o","o","o"
			,"o","o","o","o","o",
			"u","u","u","u","u","u","u","u","u","u","u",
			"y","y","y","y","y",
			"d",
			"A","A","A","A","A","A","A","A","A","A","A","A"
			,"A","A","A","A","A",
			"E","E","E","E","E","E","E","E","E","E","E",
			"I","I","I","I","I",
			"O","O","O","O","O","O","O","O","O","O","O","O"
			,"O","O","O","O","O",
			"U","U","U","U","U","U","U","U","U","U","U",
			"Y","Y","Y","Y","Y",
			"D","-", "");
			return str_replace($marTViet,$marKoDau,$cs);
		}
	}
	/**/
?>